<?php
defined('BASEPATH') OR exit('No direct script access allowed');

//体态
class Titai extends MY_Controller {

	function __construct(){
		parent::__construct();
		
		$this->load->model('User/UserTitaiModel', 'item');
	}	
	
	
	//start
	/**
	* @name 基本体态信息
	* @param page true int 页面
	* @return 
	*/
	//end
	public function basic_data(){
		$user_id = $this->user_id;
		
		$page	= $this->input->post('page',null,1);
		
		if($page<1){
			$this->err_out('页面不能小于1');
		}
		
		
		$this->load->model('User/UserPhysicalModel', 'physical');
		$new_log = $this->physical->get_new_info($user_id,$page);
		if(!$new_log){
			$this->err_out('没有数据');
		}
		
		
		$this->load->model('User/UserPhysicalTypeModel', 'physical_type');
		$this->load->model('User/UserPhysicalTargetModel', 'physical_target');		
		
		$arr = array();		
		
		$list = $new_log['list'];
		foreach($list as $k=>$v){
			$type = $this->physical_type->unique_get_info("code",$v['code']);
			
			$ls['title'] = $type['name'];
			$ls['code']  = $v['code'];
			//最新记录值
			$ls['new_value']  = $v;			
			//期望值
			$target = $this->physical_target->get_info($user_id,$type['id']);
			$ls['target_value']  = $target['value']?$target['value']:'';
			$ls['target_unit']  = $type['unit'];
			$arr[] = $ls;
		}
	
		$data['result_code'] = 0;
		$data['message']     = '获取成功';
		$data['data']        = array('list'=>$arr,'count'=>$new_log['count'],'date'=>$new_log['date']);
	
		$this->out($data);
	}
	
	//start
	/**
	* @name 体态三观
	* @param type true char //0正面1后面2侧面
	* @return 
	*/
	//end
	public function titai_info(){
		$user_id = $this->user_id;
		$type	= $this->input->post('type',null,'0');//0正面 1后面 2侧面
		
		$log_list = $this->item->get_lists(array("type"=>$type,"user_id"=>$user_id));		
		$this->load->model('User/UserTitaiConfigModel', 'TitaiConfig');
		$list = $this->TitaiConfig->get_lists(array("type"=>$type));		
		foreach($list as $k=>$v){
			$list[$k]['standard'] = '';
			$list[$k]['img'] = '';
			$list[$k]['info'] = '';
			foreach($log_list as $kk=>$vv){
				if($vv['config_id']==$v['id']){
					$list[$k]['standard'] = $vv['standard'];
					$list[$k]['img'] 	  = $vv['img'];
					$list[$k]['info'] 	  = $vv['info'];
				}
			}
		}
		
		$this->load->model('User/UserTitaiRemarkModel', 'TitaiRemark');
		$remark_list = $this->TitaiRemark->get_lists(array("type"=>$type));
		
		$arr = array(
			"list" => $list,
			"remark_list" => $remark_list
		);
		
		$data['result_code'] = 0;
		$data['message']     = '成功';
		$data['data'] 		 = $arr;
	
		$this->out($data);
	}	
		
	
}
